#!/bin/bash
set -e

python_version=${1:-3.7.11}
docker_registry=${2:-""}

script_dir="$(realpath $(dirname $0))"
source "$script_dir/util-lib.sh"
skip_if_no_changed_file_match "^(frontend|backend|concourse|tools_docker/pushpin)"

"$script_dir/install_docker"
source "$script_dir/docker-lib.sh"
start_docker "" "$docker_registry"

"$script_dir/install_backend_packages"
"$script_dir/create_backend_dirs" backend
source "$HOME/.bashrc"
pyenv shell $python_version
cd backend
pip install -r requirements.txt
python setup.py develop
# Update pyenv shims so that tracimcli is found
pyenv rehash
cp development.ini.sample development.ini
tracimcli db init -d

cd -
./setup_functionnal_tests.sh root
./install_frontend_dependencies.sh root
./build_full_frontend.sh
NO_VIRTUAL_ENV=1 ./run_dev_backend.sh cypress run
